<template>
    <div class="app">
      <header class="header">
    <span class="icon-container"><i class="el-icon-message-solid"></i></span>
    <span class="scrolling-text">欢迎来到种花吧交流论坛，请友善分享经验，严禁交流违法违规内容，遵纪守法，文明你我他</span>
</header>
        <div class="message-containers" v-for="item in commentsData" :key="item.id">
        <div class="avatar-text"  @click="chat(item.friendUserId)">
          <img :src="item.friendphoto" alt="Avatar" class="avatar" @click="click(item.friendUserId)">
          <div class="message-info">
            <el-tag type="success" v-if="item.isMutual">互关好友</el-tag>
            <h2>{{ item.usernickname }}</h2>
            <p><el-tag type="success">{{ item.lastMessage }}</el-tag><el-tag type="info">{{ item.updatedAt }}</el-tag> </p>
            <!-- <button @click="del(item.followingId)">取消关注</button> -->
          </div>
        </div>
      </div>
    </div>
  </template>
  
  <script>
  export default {
    data() {
      return {
        commentsData: [],
      }
    },
    created() {
      //请求分页查询数据
      this.load()
    },
    methods: {
      load() {
        this.request.get("/friends/listByUserId").then(res => {
          this.commentsData = res.data
          console.log(this.commentsData);
        })
      },
      del(id) {
        this.request.post("/follows/del?id=" + id)
          .then(res => {
            this.load();
            console.log(res);
          })
          .catch(error => {
            console.error("Error del user data:", error);
          });
      },
      click(id) {
        this.$router.push(`/otherprofile/${id}`);
      },
      chat(id) {
        this.$router.push(`/chat/${id}`);
      }
    }
  }
  
  </script>
  
  <style scoped>
.app {
  display: grid;
  grid-template-rows: auto 1fr;
  grid-template-columns: 100%;
  height: 100vh;
  box-shadow: 2px 2px 5px 0px rgba(0, 0, 0, 0.75);
  margin-left: 15px;
  border-radius: 10px;
  background-color: white;
}

.header {
    background-color: white;
    padding: 10px;
    height: 20px;
    border-radius: 10px; /* 所有角都是10px的圆角 */
    margin-bottom: 10px;
    border: 1px solid rgb(240, 240, 240);
    display: flex;
    align-items: center;
    overflow: hidden; /* 确保超出部分被隐藏 */
    position: relative;
}

.icon-container {
    color: red;
    margin-right: 10px;
    flex-shrink: 0; /* 确保图标不会缩小 */
}

.scrolling-text {
    display: inline-block;
    white-space: nowrap; /* 防止文本换行 */
    animation: scrollText 20s linear infinite; /* 创建无限循环的滚动动画 */
}

/* 定义滚动动画 */
@keyframes scrollText {
    0% {
        transform: translateX(0);
    }
    100% {
        transform: translateX(calc(100% - 40px)); /* 调整以适应图标宽度 */
    }
}

  .comments-section {
    width: 90%;
    padding: 5px;
    box-sizing: border-box;
  }
  
  .message-containers {
    background-color: #fff;
    border-radius: 8px;
    border: 1px solid rgb(240, 240, 240);
    margin-bottom: 15px;
    padding: 10px;
    height: 120px;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
  }
  
  .message-containers:hover {
    transform: translateY(-0.5px);
    background-color: rgb(245, 245, 245);
  }
  
  .avatar-text {
    display: flex;
    align-items: flex-start;
  }
  
  .avatar {
    border-radius: 50%;
    width: 50px;
    height: 50px;
    margin-right: 20px;
    margin-top: 30px;
    margin-left: 20px;
  }
  
  .message-info {
    flex-grow: 1;
  }
  
  .el-tag{
    margin-right: 3px;
  }
  .delete-button {
    background-color: #e74c3c;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.3s ease;
  }
  
  .delete-button:hover {
    background-color: #c0392b;
  }
  
  </style>